package com.jpf.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.ResultSet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.jpf.demo.Goods;
import com.jpf.demo.Page;
import com.jpf.service.GoodsService;
@WebServlet("/ShowList.do")
public class ShowList extends HttpServlet {
	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("text/html;charset=utf-8");
		request.setCharacterEncoding("utf-8");
		HttpSession session = request.getSession();
		GoodsService goodsService = new GoodsService();
		// List<Goods> userList = GoodsService.getAllGoodsInfo();
		String pageNow = request.getParameter("pageNow");
		String gname =(String)session.getAttribute("gname");
		if (pageNow == null||pageNow.isEmpty()) {//如果当前页为空或者首次使用则pageNow=1
			if(gname==null||gname=="") {
			Page<Goods> goodsList = goodsService.queryPage(5, 1);
			request.setAttribute("goodsList", goodsList);
			
			}
			else {
				Page<Goods> goodsList = goodsService.queryPage(5, 1, gname);
				request.setAttribute("goodsList", goodsList);
			}
		}else {
			if(gname==null||gname=="") {
			Page<Goods> goodsList = goodsService.queryPage(5, Integer.parseInt(pageNow));
			request.setAttribute("goodsList", goodsList);
			}
			else {
				Page<Goods> goodsList = goodsService.queryPage(5, Integer.parseInt(pageNow), gname);
				request.setAttribute("goodsList", goodsList);
			}
		}
		request.getRequestDispatcher("admin/list.jsp").forward(request, response);
	}
}

